package com.example.controller;

import com.example.pojo.AjaxResult;
import com.example.pojo.Mission;
import com.example.service.ROVService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.example.pojo.AjaxResult.PARAM_ERROR;

@RestController
public class ROVController {
    @Autowired
    private ROVService rovService;
    /**
    查询ROV状态信息
    */
    @PostMapping("/Info")
    public AjaxResult<?> getInfo(@RequestBody Map<String, String> request) {
        return AjaxResult.success(rovService.getInfo(request.get("content")));
    }
    /**
    查询ROV故障信息
    */
    @PostMapping("/Fault")
    public AjaxResult<?> getFault(@RequestBody Map<String, String> request) {
        return AjaxResult.success(rovService.getFault(request.get("content")));
    }
    /**
    查询ROV工作报告
    */
    @PostMapping("/Summary")
    public AjaxResult<?> getSummary(@RequestBody Mission mission) {
        return AjaxResult.success(rovService.getSummary(mission));
    }

    @PostMapping("/newMission")
    public AjaxResult<?> newMission(@RequestBody Mission mission){
        rovService.createMission(mission);
        return AjaxResult.success();
    }

    @GetMapping("/listMission")
    public AjaxResult<?> listMission(){
        return AjaxResult.success(rovService.queryAllMission());
    }

    @PostMapping("/generateMission")
    public AjaxResult<?> generateMission(@RequestBody Mission mission){
        return AjaxResult.success(rovService.generateLocation(mission));
    }

    @PostMapping("/rec")
    public AjaxResult<?> rec(@RequestBody String type){
        return AjaxResult.success(rovService.recommend(type));
    }

    /**
     * 调试使用，查看当前任务记忆
     * @return
     */
    @GetMapping("/memo")
    public AjaxResult<?> memo(String id){
        return AjaxResult.success(rovService.getMemo(id));
    }

    /**
     * ROV状态监控
     */
    @PostMapping("/logs")
    public AjaxResult<?> logs(@RequestBody Mission mission){
        return AjaxResult.success(rovService.getLogs(mission));
    }

    /**
     * 获取Redis具体数据
     * @param type
     * @return AjaxResult-Map
     */
    @GetMapping("/getData")
    public AjaxResult<?> redisTest(String type){
        if(type.equals("ROV")){
            return AjaxResult.success(rovService.GetROVData());
        }
        else if(type.equals("作业舱")){
            return AjaxResult.success(rovService.GetZYCData());
        }
        else if(type.equals("保障监控")){
            return AjaxResult.success(rovService.GetBZJKData());
        }
        else if(type.equals("导航")){
            return AjaxResult.success(rovService.GetGUIDEData());
        }
        else if(type.equals("打捞本体")){
            return AjaxResult.success(rovService.GetDLBTData());
        }
        else if(type.equals("机械臂")){
            return AjaxResult.success(rovService.GetJXBData());
        }
        else if(type.equals("权限切换")){
            return AjaxResult.success(rovService.GetQXQHData());
        }
        else if(type.equals("模块化")){
            return AjaxResult.success(rovService.GetMKHDZData());
        }
        else if(type.equals("铺缆")){
            return AjaxResult.success(rovService.GetPLData());
        }
        return AjaxResult.error(PARAM_ERROR, "参数错误");
    }

    /**
     * 设置Redis具体数据
     * @param request
     * @return AjaxResult-Boolean
     */
    @PostMapping("/setData")
    public AjaxResult<?> redisSetData(@RequestBody Map<String, Object> request){
        Boolean result = false;
        if(request.get("type").equals("ROV")){
            result = rovService.SetROVData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("作业舱")){
            result = rovService.SetZYCData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("保障监控")){
            result = rovService.SetBZJKData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("导航")){
            result = rovService.SetGUIDEData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("打捞本体")){
            result = rovService.SetDLBTData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("机械臂")){
            result = rovService.SetJXBData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("权限切换")){
            result = rovService.SetQXQHData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("模块化")){
            result = rovService.SetMKHData((Map<String, String>) request.get("data"));
        }
        else if(request.get("type").equals("铺缆")){
            result = rovService.SetPLData((Map<String, String>) request.get("data"));
        }
        if(result){
            return AjaxResult.success();
        }
        return AjaxResult.fail("存在无法解析的数据名或数据值");
    }
}
